using System.Web.UI;

[assembly: WebResource("JQuery.WebKit.WebGrid.WebGrid.js", "text/javascript")]
[assembly: WebResource("JQuery.WebKit.WebGrid.WebGrid.min.js", "text/javascript")]
[assembly: WebResource("JQuery.WebKit.WebGrid.locale.grid.locale-en.js", "text/javascript")]
[assembly: WebResource("JQuery.WebKit.WebGrid.locale.grid.locale-en.min.js", "text/javascript")]
namespace JQuery.WebKit
{
    using System;
    using System.Collections;
    using System.Collections.Specialized;
    using System.ComponentModel;
    using System.Data;
    using System.Data.Common;
    using System.Drawing;
    using System.IO;
    using System.Reflection;
    using System.Security.Permissions;
    using System.Text;
    using System.Web;
    using System.Web.Script.Serialization;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using JQuery.WebKit.WebCommon;

    [Designer("JQuery.WebKit.Design.WebGridDesigner"),
        //ToolboxData("<{0}:WebGrid runat=server></{0}:WebGrid>"), 
    AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal),
    AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
    public class WebGrid : CompositeDataBoundControl, IPostBackDataHandler, IPostBackEventHandler
    {
        private JQuery.WebKit.AddDialogSettings _addDialogSettings;
        private JQuery.WebKit.AjaxCallBackMode _ajaxCallBackMode;
        private bool _ajaxCallModeResolved;
        private JQuery.WebKit.AppearanceSettings _appearanceSettings;
        private JQuery.WebKit.ClientSideEvents _clientSideEvents;
        private WebGridColumnCollection _columnCollection;
        private bool _dataSourceSorted;
        private JQuery.WebKit.DeleteDialogSettings _deleteDialogSettings;
        private JQuery.WebKit.EditDialogSettings _editDialogSettings;
        private JQuery.WebKit.EditInlineCellSettings _editInlineCellSettings;
        private JQuery.WebKit.GroupSettings _groupSettings;
        private JQuery.WebKit.HierarchySettings _hierarchySettings;
        private JQuery.WebKit.PagerSettings _pagerSettings;
        private JQuery.WebKit.SearchDialogSettings _searchDialogSettings;
        private DataSourceSelectArguments _selectArguments;
        private JQuery.WebKit.SortSettings _sortSettings;
        private JavaScriptSerializer _sr;
        private JQuery.WebKit.ToolBarSettings _toolBarSettings;
        private int _totalRows;
        protected static readonly object EventCellBinding = new object();
        private static readonly object EventCellBound = new object();
        private static readonly object EventDataRequested = new object();
        private static readonly object EventDataRequesting = new object();
        private static readonly object EventRowAdded = new object();
        protected static readonly object EventRowAdding = new object();
        private static readonly object EventRowDeleted = new object();
        private static readonly object EventRowDeleting = new object();
        private static readonly object EventRowEdited = new object();
        private static readonly object EventRowEditing = new object();
        private static readonly object EventRowSelecting = new object();
        private static readonly object EventSearched = new object();
        private static readonly object EventSearching = new object();
        private static readonly object EventSorted = new object();
        private static readonly object EventSorting = new object();

        [Description("GridView_OnSearching"), Category("Action")]
        public event WebGridCellBindEventHandler CellBinding
        {
            add
            {
                base.Events.AddHandler(EventCellBinding, value);
            }
            remove
            {
                base.Events.RemoveHandler(EventCellBinding, value);
            }
        }

        [Description("GridView_OnSearched"), Category("Action")]
        public event WebGridCellBindEventHandler CellBound
        {
            add
            {
                base.Events.AddHandler(EventCellBound, value);
            }
            remove
            {
                base.Events.RemoveHandler(EventCellBound, value);
            }
        }

        [Category("Action"), Description("GridView_OnSearched")]
        public event WebGridDataRequestedEventHandler DataRequested
        {
            add
            {
                base.Events.AddHandler(EventDataRequested, value);
            }
            remove
            {
                base.Events.RemoveHandler(EventDataRequested, value);
            }
        }

        [Description("GridView_OnSearched"), Category("Action")]
        public event WebGridDataRequestEventHandler DataRequesting
        {
            add
            {
                base.Events.AddHandler(EventDataRequesting, value);
            }
            remove
            {
                base.Events.RemoveHandler(EventDataRequesting, value);
            }
        }

        [Category("Action"), Description("GridView_OnSearched")]
        public event EventHandler RowAdded
        {
            add
            {
                base.Events.AddHandler(EventRowAdded, value);
            }
            remove
            {
                base.Events.RemoveHandler(EventRowAdded, value);
            }
        }

        [Description("GridView_OnSearching"), Category("Action")]
        public event WebGridRowAddEventHandler RowAdding
        {
            add
            {
                base.Events.AddHandler(EventRowAdding, value);
            }
            remove
            {
                base.Events.RemoveHandler(EventRowAdding, value);
            }
        }

        [Category("Action"), Description("GridView_OnSearched")]
        public event EventHandler RowDeleted
        {
            add
            {
                base.Events.AddHandler(EventRowDeleted, value);
            }
            remove
            {
                base.Events.RemoveHandler(EventRowDeleted, value);
            }
        }

        [Description("GridView_OnSearching"), Category("Action")]
        public event WebGridRowDeleteEventHandler RowDeleting
        {
            add
            {
                base.Events.AddHandler(EventRowDeleting, value);
            }
            remove
            {
                base.Events.RemoveHandler(EventRowDeleting, value);
            }
        }

        [Category("Action"), Description("GridView_OnSearched")]
        public event EventHandler RowEdited
        {
            add
            {
                base.Events.AddHandler(EventRowEdited, value);
            }
            remove
            {
                base.Events.RemoveHandler(EventRowEdited, value);
            }
        }

        [Description("GridView_OnSearching"), Category("Action")]
        public event WebGridRowEditEventHandler RowEditing
        {
            add
            {
                base.Events.AddHandler(EventRowEditing, value);
            }
            remove
            {
                base.Events.RemoveHandler(EventRowEditing, value);
            }
        }

        [Category("Action"), Description("GridView_OnSearching")]
        public event WebGridRowSelectEventHandler RowSelecting
        {
            add
            {
                base.Events.AddHandler(EventRowSelecting, value);
            }
            remove
            {
                base.Events.RemoveHandler(EventRowSelecting, value);
            }
        }

        [Category("Action"), Description("GridView_OnSearched")]
        public event EventHandler Searched
        {
            add
            {
                base.Events.AddHandler(EventSearched, value);
            }
            remove
            {
                base.Events.RemoveHandler(EventSearched, value);
            }
        }

        [Category("Action"), Description("GridView_OnSearching")]
        public event WebGridSearchEventHandler Searching
        {
            add
            {
                base.Events.AddHandler(EventSearching, value);
            }
            remove
            {
                base.Events.RemoveHandler(EventSearching, value);
            }
        }

        [Description("GridView_OnSorted"), Category("Action")]
        public event EventHandler Sorted
        {
            add
            {
                base.Events.AddHandler(EventSorted, value);
            }
            remove
            {
                base.Events.RemoveHandler(EventSorted, value);
            }
        }

        [Description("GridView_OnSorting"), Category("Action")]
        public event WebGridSortEventHandler Sorting
        {
            add
            {
                base.Events.AddHandler(EventSorting, value);
            }
            remove
            {
                base.Events.RemoveHandler(EventSorting, value);
            }
        }

        public Unit MaxHeight { get; set; }

        public new JPage Page
        {
            get { return base.Page as JPage; }
        }

        protected override int CreateChildControls(IEnumerable dataSource, bool dataBinding)
        {
            return 0;
        }

        protected override DataSourceSelectArguments CreateDataSourceSelectArguments()
        {
            Convert.ToInt32(HttpContext.Current.Request.QueryString["rows"]);
            Convert.ToInt32(HttpContext.Current.Request.QueryString["page"]);
            string sortExpression = HttpContext.Current.Request.QueryString["sidx"];
            string sortDirection = HttpContext.Current.Request.QueryString["sord"];
            string search = HttpContext.Current.Request.QueryString["_search"];
            DataSourceSelectArguments arguments = new DataSourceSelectArguments();
            DataSourceView data = this.GetData();
            if (data is LinqDataSourceView)
            {
                LinqDataSourceView view2 = data as LinqDataSourceView;
                SearchCriteriaCollection collection = null;
                view2.Where = this.GetWhereClause(search, true, out collection);
            }
            if (data.CanSort && (sortExpression != null))
            {
                WebGridSortEventArgs e = new WebGridSortEventArgs(sortExpression, sortDirection);
                this.OnSorting(e);
                this._dataSourceSorted = true;
                if (!e.Cancel)
                {
                    if (this.GroupSettings.GroupFields.Count > 0)
                    {
                        string str4 = sortExpression.Split(new char[] { ' ' })[0];
                        string str5 = sortExpression.Split(new char[] { ' ' })[1].Split(new char[] { ',' })[0];
                        sortExpression = sortExpression.Split(new char[] { ',' })[1];
                        arguments.SortExpression = str4 + " " + str5;
                    }
                    if ((sortExpression != null) && (sortExpression == " "))
                    {
                        sortExpression = "";
                    }
                    if (!string.IsNullOrEmpty(sortExpression))
                    {
                        if ((this.GroupSettings.GroupFields.Count > 0) && !arguments.SortExpression.EndsWith(","))
                        {
                            arguments.SortExpression = arguments.SortExpression + ",";
                        }
                        arguments.SortExpression = arguments.SortExpression + sortExpression + " " + sortDirection;
                    }
                }
            }
            if (data.CanPage)
            {
                if (data.CanRetrieveTotalRowCount)
                {
                    arguments.RetrieveTotalRowCount = true;
                    arguments.MaximumRows = this.PagerSettings.PageSize;
                }
                else
                {
                    arguments.MaximumRows = -1;
                }
                arguments.StartRowIndex = this.PagerSettings.PageSize * (this.PagerSettings.CurrentPage - 1);
            }
            return arguments;
        }

        public override void DataBind()
        {
        }

        private void EmitResponse(string responseText)
        {
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(responseText);
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
        }

        private void EnforceColumnContraints()
        {
            string message = "Columns should be explicitly defined with at least DataField set to the respective datasource field, e.g. \r\n                                        <web:WebGrid ...>\r\n                                             <Columns>\r\n                                                <web:WebGridColumn DataField='OrderID' PrimaryKey='True' />\r\n                                                <web:WebGridColumn DataField='Freight' Editable='true' Sortable='false'  />\r\n                                                <web:WebGridColumn DataField='OrderDate' DataFormatString='{0:d}' />\r\n                                                <web:WebGridColumn DataField='ShipCity' />\r\n                                            </Columns>\r\n                                            ...";
            if (this.Columns.Count == 0)
            {
                throw new Exception(message);
            }
        }

        public void ExportToExcel(string fileName)
        {
            DataGrid child = new DataGrid();
            this.Controls.Add(child);
            child.AutoGenerateColumns = false;
            child.ID = this.ID + "_exportGrid";
            foreach (WebGridColumn column in this.Columns)
            {
                BoundColumn column2 = new BoundColumn();
                column2.DataField = column.DataField;
                string str = string.IsNullOrEmpty(column.HeaderText) ? column.DataField : column.HeaderText;
                column2.HeaderText = str;
                column2.DataFormatString = column.DataFormatString;
                column2.FooterText = column.FooterValue;
                child.Columns.Add(column2);
            }
            child.DataSource = this.DataSource;
            child.DataSourceID = this.DataSourceID;
            child.DataBind();
            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
            HttpContext.Current.Response.ContentType = "application/excel";
            StringWriter writer = new StringWriter();
            HtmlTextWriter writer2 = new HtmlTextWriter(writer);
            child.RenderControl(writer2);
            HttpContext.Current.Response.Write(writer.ToString());
            HttpContext.Current.Response.End();
        }

        internal Control FindControlRecursive(Control root, string id)
        {
            if (root.ID == id)
            {
                return root;
            }
            foreach (Control control in root.Controls)
            {
                Control control2 = this.FindControlRecursive(control, id);
                if (control2 != null)
                {
                    return control2;
                }
            }
            return null;
        }

        private string GetAddOptions()
        {
            JsonAddDialog dialog = new JsonAddDialog(this);
            return dialog.Process();
        }

        private string GetChildSubGridJavaScript()
        {
            StringBuilder builder = new StringBuilder();
            //builder.Append("<script type='text/javascript'>\n");
            builder.AppendFormat("function showSubGrid_{0}(subgrid_id, row_id, message, suffix) {{", this.ID);
            builder.Append("var subgrid_table_id, pager_id;\r\n\t\t                subgrid_table_id = subgrid_id+'_t';\r\n\t\t                pager_id = 'p_'+ subgrid_table_id;\r\n                        if (suffix) { subgrid_table_id += suffix; pager_id += suffix;  }\r\n                        if (message) jQuery('#'+subgrid_id).append(message);                        \r\n\t\t                jQuery('#'+subgrid_id).append('<table id=' + subgrid_table_id + ' class=scroll></table><div id=' + pager_id + ' class=scroll></div>');\r\n                ");
            builder.Append(this.GetStartupOptions(true));
            builder.Append("}");
            //builder.Append("</script>");
            return builder.ToString();
        }

        private string GetColModel()
        {
            Hashtable[] hashtableArray = new Hashtable[this.Columns.Count];
            for (int i = 0; i < this.Columns.Count; i++)
            {
                JsonColModel model = new JsonColModel(this.Columns[i], this);
                hashtableArray[i] = model.JsonValues;
            }
            return JsonColModel.RemoveQuotesForJavaScriptMethods(this._sr.Serialize(hashtableArray), this);
        }

        private string GetColNames()
        {
            string[] strArray = new string[this.Columns.Count];
            for (int i = 0; i < this.Columns.Count; i++)
            {
                WebGridColumn column = this.Columns[i];
                strArray[i] = string.IsNullOrEmpty(column.HeaderText) ? column.DataField : column.HeaderText;
            }
            return this._sr.Serialize(strArray);
        }

        private WebGridColumn GetColumnFromDataTable(string columnName)
        {
            foreach (WebGridColumn column in this.Columns)
            {
                if (column.DataField == columnName)
                {
                    return column;
                }
            }
            return null;
        }

        private DataTable GetDataTableFromIEnumerable(IEnumerable en)
        {
            DataTable table = new DataTable();
            DataView view = en as DataView;
            if (view != null)
            {
                return view.ToTable();
            }
            if (en != null)
            {
                table = this.ObtainDataTableFromIEnumerable(en);
            }
            return table;
        }

        private string GetDelOptions()
        {
            JsonDelDialog dialog = new JsonDelDialog(this);
            return dialog.Process();
        }

        private string GetEditOptions()
        {
            JsonEditDialog dialog = new JsonEditDialog(this);
            return dialog.Process();
        }

        private Hashtable GetFooterInfo()
        {
            Hashtable hashtable = new Hashtable();
            if (this.AppearanceSettings.ShowFooter)
            {
                foreach (WebGridColumn column in this.Columns)
                {
                    hashtable[column.DataField] = column.FooterValue;
                }
            }
            return hashtable;
        }

        private string GetJQuerySubmit()
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat("\r\n                        var _theForm = document.getElementsByTagName('FORM')[0];\r\n                        jQuery(_theForm).submit( function() \r\n                        {{  \r\n                            jQuery('#{0}').attr('value', jQuery('#{1}').getGridParam('selrow'));                            \r\n                        }});\r\n                       ", this.ClientID + "_SelectedRow", this.ClientID, this.ClientID + "_CurrentPage");
            return builder.ToString();
        }

        private string GetLoadErrorHandler()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("\n\rfunction WebGrid_aspnet_loadErrorHandler(xht, st, handler) {");
            builder.Append("jQuery(document.body).css('font-size','100%'); jQuery(document.body).html(xht.responseText);");
            builder.Append("}");
            return builder.ToString();
        }

        private string GetMultiKeyString(JQuery.WebKit.MultiSelectKey key)
        {
            switch (key)
            {
                case JQuery.WebKit.MultiSelectKey.Shift:
                    return "shiftKey";

                case JQuery.WebKit.MultiSelectKey.Ctrl:
                    return "ctrlKey";

                case JQuery.WebKit.MultiSelectKey.Alt:
                    return "altKey";
            }
            throw new Exception("Should not be here.");
        }

        private DataTable GetPagedDataTable(int startIndex, int endIndex, DataTable dt)
        {
            DataTable table = new DataTable();
            foreach (DataColumn column in dt.Columns)
            {
                table.Columns.Add(column.ColumnName, column.DataType);
            }
            for (int i = startIndex; i < endIndex; i++)
            {
                DataRow row = table.NewRow();
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    row[j] = dt.Rows[i][j];
                }
                table.Rows.InsertAt(row, 0);
            }
            return table;
        }

        private int GetPrimaryKeyIndex()
        {
            foreach (WebGridColumn column in this.Columns)
            {
                if (column.PrimaryKey)
                {
                    return this.Columns.IndexOf(column);
                }
            }
            return 0;
        }

        private string GetSearchOptions()
        {
            JsonSearchDialog dialog = new JsonSearchDialog(this);
            dialog.Process();
            return this._sr.Serialize(dialog.JsonValues);
        }

        private string GetSelectedRowPostBack()
        {
            if (((WebGridRowSelectEventHandler)base.Events[EventRowSelecting]) != null)
            {
                StringBuilder builder = new StringBuilder();
                builder.AppendFormat("\r\n                    jQuery('#{0}').bind('click', function() {{\r\n                        var grid = jQuery('#{0}');\r\n                        var rowKey = grid.getGridParam('selrow');\r\n                        var postBackScript = grid.getGridParam('postBackUrl').replace(/WebGridParams/g, rowKey);\r\n                        jQuery('#{0}_CurrentPage').attr('value', grid.getGridParam('page'));\r\n                        jQuery('#{0}_SelectedRow').attr('value', grid.getGridParam('selrow'));\r\n                        eval(postBackScript);\r\n                    }});\r\n                ", this.ClientID);
                return builder.ToString();
            }
            return string.Empty;
        }

        private string GetStartupJavascript()
        {
            StringBuilder builder = new StringBuilder();
            //builder.Append("<script type='text/javascript'>\n");
            //builder.Append("jQuery(document).ready(function() {");
            builder.Append(this.GetStartupOptions(false));
            //builder.Append("});");
            //builder.Append("</script>");
            return builder.ToString();
        }

        private string GetStartupOptions(bool subGrid)
        {
            StringBuilder sb = new StringBuilder();
            string str = subGrid ? "jQuery('#' + subgrid_table_id)" : string.Format("jQuery('#{0}')", this.ClientID);
            string str2 = subGrid ? "jQuery('#' + pager_id)" : string.Format("jQuery('#{0}')", this.ClientID + "_pager");
            string str3 = subGrid ? "&parentRowID=' + row_id + '" : string.Empty;
            string str4 = (this.DataUrl.IndexOf("?") > 0) ? "&" : "?";
            string str5 = (this.EditUrl.IndexOf("?") > 0) ? "&" : "?";
            string str6 = string.Format("{0}{1}WebGridID={2}{3}", new object[] { this.DataUrl, str4, this.ClientID, str3 });
            string str7 = string.Format("{0}{1}WebGridID={2}&editMode=1{3}", new object[] { this.EditUrl, str5, this.ClientID, str3 });
            sb.AppendFormat("{0}.jqGrid({{", str);
            sb.AppendFormat("url: '{0}'", str6);
            sb.AppendFormat(",editurl: '{0}'", str7);
            sb.AppendFormat(",datatype: 'json'", new object[0]);
            sb.AppendFormat(",page: {0}", this.PagerSettings.CurrentPage);
            sb.AppendFormat(",colNames: {0}", this.GetColNames());
            sb.AppendFormat(",colModel: {0}", this.GetColModel());
            sb.AppendFormat(",viewrecords: true", new object[0]);
            sb.AppendFormat(",scrollrows: true", new object[0]);
            sb.AppendFormat(",postBackUrl: \"{0}\"", this.Page.ClientScript.GetPostBackEventReference(this, "WebGridParams"));
            sb.AppendFormat(",editDialogOptions: {0}", this.GetEditOptions());
            sb.AppendFormat(",addDialogOptions: {0}", this.GetAddOptions());
            sb.AppendFormat(",delDialogOptions: {0}", this.GetDelOptions());
            sb.AppendFormat(",searchDialogOptions: {0}", this.GetSearchOptions());
            sb.AppendFormat(",rowNum: {0}", this.PagerSettings.PageSize.ToString());
            sb.AppendFormat(",rowList: {0}", this.PagerSettings.PageSizeOptions.ToString());
            sb.AppendFormat(",sortorder: '{0}'", this.SortSettings.InitialSortDirection.ToString().ToLower());
            sb.AppendFormat(",hidegrid: {0}", this.AppearanceSettings.ShowCaptionGridToggleButton.ToString().ToLower());
            if (!this.Width.IsEmpty)
            {
                sb.AppendFormat(",width: '{0}'", this.Width.ToString().Replace("px", ""));
            }
            if (!this.Height.IsEmpty)
            {
                sb.AppendFormat(",height: '{0}'", this.Height.ToString().Replace("px", ""));
            }
            if (!this.MaxHeight.IsEmpty)
            {
                sb.AppendFormat(",maxHeight: '{0}'", this.MaxHeight.ToString().Replace("px", ""));
            }
            if (this.ColumnReordering)
            {
                sb.Append(",sortable: true");
            }
            if (this.AutoWidth)
            {
                sb.Append(",autowidth: true");
            }
            if (!this.AppearanceSettings.HighlightRowsOnHover)
            {
                sb.Append(",hoverrows: false");
            }
            if (this.AppearanceSettings.AlternateRowBackground)
            {
                sb.Append(",altRows: true");
            }
            if (this.AppearanceSettings.ShowRowNumbers)
            {
                sb.Append(",rownumbers: true");
            }
            if (this.AppearanceSettings.RowNumbersColumnWidth != 0x19)
            {
                sb.AppendFormat(",rownumWidth: {0}", this.AppearanceSettings.RowNumbersColumnWidth.ToString());
            }
            if (!this.AppearanceSettings.ShrinkToFit)
            {
                sb.Append(",shrinkToFit: false");
            }
            if (this.AppearanceSettings.ScrollBarOffset != 0x12)
            {
                sb.AppendFormat(",scrollOffset: {0}", this.AppearanceSettings.ScrollBarOffset);
            }
            if (this.AppearanceSettings.RightToLeft)
            {
                sb.Append(",direction: 'rtl'");
            }
            if (!string.IsNullOrEmpty(this.AppearanceSettings.Caption))
            {
                sb.AppendFormat(",caption: '{0}'", this.AppearanceSettings.Caption);
            }
            if (this.AppearanceSettings.ShowFooter)
            {
                sb.Append(",footerrow: true");
                sb.Append(",userDataOnFooter: true");
            }
            if ((this.ToolBarSettings.ToolBarPosition == ToolBarPosition.Bottom) || (this.ToolBarSettings.ToolBarPosition == ToolBarPosition.TopAndBottom))
            {
                sb.AppendFormat(",pager: {0}", str2);
            }
            if ((this.ToolBarSettings.ToolBarPosition == ToolBarPosition.Top) || (this.ToolBarSettings.ToolBarPosition == ToolBarPosition.TopAndBottom))
            {
                sb.Append(",toppager: true");
            }
            if (this.PagerSettings.ScrollBarPaging)
            {
                sb.AppendFormat(",scroll: 1", new object[0]);
            }
            if (!string.IsNullOrEmpty(this.PagerSettings.NoRowsMessage))
            {
                sb.AppendFormat(",emptyrecords: '{0}'", this.PagerSettings.NoRowsMessage.ToString());
            }
            if (this.RenderingMode == JQuery.WebKit.RenderingMode.Optimized)
            {
                sb.Append(",gridview: true");
            }
            if (!string.IsNullOrEmpty(this.SortSettings.InitialSortColumn))
            {
                sb.AppendFormat(",sortname: '{0}'", this.SortSettings.InitialSortColumn);
            }
            sb.AppendFormat(",viewsortcols: [{0},'{1}',{2}]", "false", this.SortSettings.SortIconsPosition.ToString().ToLower(), (this.SortSettings.SortAction == SortAction.ClickOnHeader) ? "true" : "false");
            if ((this.HierarchySettings.HierarchyMode == HierarchyMode.Parent) || (this.HierarchySettings.HierarchyMode == HierarchyMode.ParentAndChild))
            {
                sb.Append(",subGrid: true");
            }
            if (this.MultiSelect)
            {
                sb.Append(",multiselect: true");
                if (this.MultiSelectMode == JQuery.WebKit.MultiSelectMode.SelectOnCheckBoxClickOnly)
                {
                    sb.AppendFormat(",multiboxonly: true", this.MultiSelect.ToString().ToLower());
                }
                if (this.MultiSelectKey != JQuery.WebKit.MultiSelectKey.None)
                {
                    sb.AppendFormat(",multikey: '{0}'", this.GetMultiKeyString(this.MultiSelectKey));
                }
            }
            if (this.EditInlineCellSettings.Enabled)
            {
                sb.Append(",cellEdit:true");
                sb.Append(",cellsubmit:'remote'");
                sb.AppendFormat(",cellurl:'{0}'", str7);
            }
            if (this.GroupSettings.GroupFields.Count > 0)
            {
                sb.Append(",grouping:true");
                sb.Append(",groupingView: {");
                sb.AppendFormat("groupField: ['{0}']", this.GroupSettings.GroupFields[0].DataField);
                sb.AppendFormat(",groupColumnShow: [{0}]", this.GroupSettings.GroupFields[0].ShowGroupColumn.ToString().ToLower());
                sb.AppendFormat(",groupText: ['{0}']", this.GroupSettings.GroupFields[0].HeaderText);
                sb.AppendFormat(",groupOrder: ['{0}']", this.GroupSettings.GroupFields[0].GroupSortDirection.ToString().ToLower());
                sb.AppendFormat(",groupSummary: [{0}]", this.GroupSettings.GroupFields[0].ShowGroupSummary.ToString().ToLower());
                sb.AppendFormat(",groupCollapse: {0}", this.GroupSettings.CollapseGroups.ToString().ToLower());
                sb.AppendFormat(",groupDataSorted: true", new object[0]);
                sb.Append("}");
            }
            this.RenderClientSideEvents(sb, this.ClientSideEvents);
            sb.AppendFormat("}})", new object[0]);
            sb.Append(this.GetToolBarOptions(subGrid));
            sb.Append(this.GetLoadErrorHandler());
            if (!subGrid)
            {
                sb.Append(this.GetJQuerySubmit());
                sb.Append(this.GetSelectedRowPostBack());
                sb.Append(this.RestoreSelectedState());
            }
            if (this.ToolBarSettings.ShowSearchToolBar)
            {
                sb.AppendFormat("jQuery('#{0}').filterToolbar();", this.ClientID);
            }
            return sb.ToString();
        }

        private string GetToolBarOptions(bool subGrid)
        {
            StringBuilder builder = new StringBuilder();
            if (!this.ShowToolBar)
            {
                return string.Empty;
            }
            JsonToolBar bar = new JsonToolBar(this.ToolBarSettings);
            if (!subGrid)
            {
                builder.AppendFormat(".navGrid('#{0}',{1},{2},{3},{4},{5} );", new object[] { this.ClientID + "_pager", this._sr.Serialize(bar), string.Format("jQuery('#{0}').getGridParam('editDialogOptions')", this.ClientID), string.Format("jQuery('#{0}').getGridParam('addDialogOptions')", this.ClientID), string.Format("jQuery('#{0}').getGridParam('delDialogOptions')", this.ClientID), string.Format("jQuery('#{0}').getGridParam('searchDialogOptions')", this.ClientID) });
            }
            else
            {
                builder.AppendFormat(".navGrid('#' + pager_id,{0},{1},{2},{3},{4} );", new object[] { this._sr.Serialize(bar), "jQuery('#' + subgrid_table_id).getGridParam('editDialogOptions')", "jQuery('#' + subgrid_table_id).getGridParam('addDialogOptions')", "jQuery('#' + subgrid_table_id).getGridParam('delDialogOptions')", "jQuery('#' + subgrid_table_id).getGridParam('searchDialogOptions')" });
            }
            return builder.ToString();
        }

        private string GetWhereClause(string search, bool isLinq, out SearchCriteriaCollection criteriaList)
        {
            string str = string.Empty;
            criteriaList = null;
            if (string.IsNullOrEmpty(search) && !Convert.ToBoolean(search))
            {
                return str;
            }
            return new BaseSearching(this).GetWhereClause(isLinq, out criteriaList);
        }

        private void HandleDelete(WebGridRowDeleteEventArgs e)
        {
            if (base.IsBoundUsingDataSourceID)
            {
                OrderedDictionary keys = new OrderedDictionary();
                OrderedDictionary oldValues = new OrderedDictionary();
                new OrderedDictionary();
                DataSourceView data = this.GetData();
                if (data == null)
                {
                    throw new HttpException("DataSource is null in edit mode (on update)");
                }
                foreach (WebGridColumn column in this.Columns)
                {
                    if (column.PrimaryKey)
                    {
                        keys.Add(column.DataField, e.RowKey);
                    }
                }
                data.Delete(keys, oldValues, new DataSourceViewOperationCallback(this.HandleDeleteCallback));
            }
        }

        private bool HandleDeleteCallback(int affectedRows, Exception ex)
        {
            if (ex != null)
            {
                throw ex;
            }
            return true;
        }

        private void HandleInsert(WebGridRowAddEventArgs e)
        {
            if (base.IsBoundUsingDataSourceID)
            {
                OrderedDictionary values = new OrderedDictionary();
                DataSourceView data = this.GetData();
                if (data == null)
                {
                    throw new HttpException("DataSource is null in edit mode (on update)");
                }
                foreach (string str in e.RowData.Keys)
                {
                    values.Add(str, e.RowData[str]);
                }
                data.Insert(values, new DataSourceViewOperationCallback(this.HandleInsertCallback));
            }
        }

        private bool HandleInsertCallback(int affectedRows, Exception ex)
        {
            if (ex != null)
            {
                throw ex;
            }
            return true;
        }

        private void HandleUpdate()
        {
            if (base.IsBoundUsingDataSourceID && (this.GetData() == null))
            {
                throw new HttpException("DataSource is null in edit mode (on update)");
            }
        }

        private void HandleUpdate(WebGridRowEditEventArgs e)
        {
            if (base.IsBoundUsingDataSourceID)
            {
                OrderedDictionary keys = new OrderedDictionary();
                OrderedDictionary values = new OrderedDictionary();
                OrderedDictionary oldValues = new OrderedDictionary();
                DataSourceView data = this.GetData();
                if (data == null)
                {
                    throw new HttpException("DataSource is null in edit mode (on update)");
                }
                foreach (WebGridColumn column in this.Columns)
                {
                    if (column.PrimaryKey)
                    {
                        keys.Add(column.DataField, e.RowData[column.DataField]);
                    }
                    if (column.Editable)
                    {
                        values.Add(column.DataField, e.RowData[column.DataField]);
                    }
                }
                data.Update(keys, values, oldValues, new DataSourceViewOperationCallback(this.HandleUpdateCallback));
            }
        }

        private bool HandleUpdateCallback(int affectedRows, Exception ex)
        {
            if (ex != null)
            {
                throw ex;
            }
            return true;
        }

        public virtual bool IsBindableType(Type type)
        {
            if (type == null)
            {
                return false;
            }
            Type underlyingType = Nullable.GetUnderlyingType(type);
            if (underlyingType != null)
            {
                type = underlyingType;
            }
            if (((!type.IsPrimitive && (type != typeof(string))) && ((type != typeof(DateTime)) && (type != typeof(decimal)))) && ((type != typeof(Guid)) && (type != typeof(DateTimeOffset))))
            {
                return (type == typeof(TimeSpan));
            }
            return true;
        }

        public bool IsGridRequest()
        {
            string str = HttpContext.Current.Request.QueryString["WebGridID"];
            return (!string.IsNullOrEmpty(str) && (str == this.ClientID));
        }

        public bool LoadPostData(string postDataKey, NameValueCollection postCollection)
        {
            string[] strArray = postCollection[postDataKey].Split(new char[] { ',' });
            string str = strArray[0];
            string str2 = strArray[1];
            if (!string.IsNullOrEmpty(str))
            {
                this.SelectedRow = str;
            }
            if (!string.IsNullOrEmpty(str2))
            {
                this.PagerSettings.CurrentPage = Convert.ToInt32(str2);
            }
            return false;
        }

        protected override void LoadViewState(object savedState)
        {
            if (savedState != null)
            {
                object[] objArray = (object[])savedState;
                base.LoadViewState(objArray[0]);
                if (objArray[1] != null)
                {
                    ((IStateManager)this.ToolBarSettings).LoadViewState(objArray[1]);
                }
                if (objArray[2] != null)
                {
                    ((IStateManager)this.EditDialogSettings).LoadViewState(objArray[2]);
                }
                if (objArray[3] != null)
                {
                    ((IStateManager)this.SearchDialogSettings).LoadViewState(objArray[3]);
                }
                if (objArray[4] != null)
                {
                    ((IStateManager)this.PagerSettings).LoadViewState(objArray[4]);
                }
                if (objArray[5] != null)
                {
                    ((IStateManager)this.SortSettings).LoadViewState(objArray[5]);
                }
                if (objArray[6] != null)
                {
                    ((IStateManager)this.AppearanceSettings).LoadViewState(objArray[6]);
                }
                if (objArray[7] != null)
                {
                    ((IStateManager)this.AddDialogSettings).LoadViewState(objArray[7]);
                }
                if (objArray[8] != null)
                {
                    ((IStateManager)this.DeleteDialogSettings).LoadViewState(objArray[8]);
                }
                if (objArray[9] != null)
                {
                    ((IStateManager)this.EditInlineCellSettings).LoadViewState(objArray[9]);
                }
                if (objArray[10] != null)
                {
                    ((IStateManager)this.GroupSettings).LoadViewState(objArray[10]);
                }
            }
            else
            {
                base.LoadViewState(null);
            }
        }

        private DataTable ObtainDataTableFromIEnumerable(IEnumerable ien)
        {
            DataTable table = new DataTable();
            foreach (object obj2 in ien)
            {
                if (obj2 is DbDataRecord)
                {
                    DbDataRecord record = obj2 as DbDataRecord;
                    if (table.Columns.Count == 0)
                    {
                        foreach (WebGridColumn column in this.Columns)
                        {
                            table.Columns.Add(column.DataField);
                        }
                    }
                    DataRow row = table.NewRow();
                    foreach (WebGridColumn column2 in this.Columns)
                    {
                        row[column2.DataField] = record[column2.DataField];
                    }
                    table.Rows.Add(row);
                    continue;
                }
                PropertyInfo[] properties = obj2.GetType().GetProperties();
                if (table.Columns.Count == 0)
                {
                    foreach (PropertyInfo info in properties)
                    {
                        Type propertyType = info.PropertyType;
                        if (propertyType.IsGenericType && (propertyType.GetGenericTypeDefinition() == typeof(Nullable<>)))
                        {
                            propertyType = Nullable.GetUnderlyingType(propertyType);
                        }
                        table.Columns.Add(info.Name, propertyType);
                    }
                }
                DataRow row2 = table.NewRow();
                foreach (PropertyInfo info2 in properties)
                {
                    object obj3 = info2.GetValue(obj2, null);
                    if (obj3 != null)
                    {
                        row2[info2.Name] = obj3;
                    }
                    else
                    {
                        row2[info2.Name] = DBNull.Value;
                    }
                }
                table.Rows.Add(row2);
            }
            return table;
        }

        protected internal virtual void OnCellBinding(WebGridCellBindEventArgs e)
        {
            WebGridCellBindEventHandler handler = (WebGridCellBindEventHandler)base.Events[EventCellBinding];
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected internal virtual void OnCellBound(WebGridCellBindEventArgs e)
        {
            WebGridCellBindEventHandler handler = (WebGridCellBindEventHandler)base.Events[EventCellBound];
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected internal virtual void OnDataRequested(WebGridDataRequestedEventArgs e)
        {
            WebGridDataRequestedEventHandler handler = (WebGridDataRequestedEventHandler)base.Events[EventDataRequested];
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected internal virtual void OnDataRequesting(WebGridDataRequestEventArgs e)
        {
            WebGridDataRequestEventHandler handler = (WebGridDataRequestEventHandler)base.Events[EventDataRequesting];
            if (handler != null)
            {
                handler(this, e);
            }
        }

        private void OnDataSourceViewSelectCallback()
        {
            switch (this.AjaxCallBackMode)
            {
                //case JQuery.WebKit.AjaxCallBackMode.RequestData:
                //case JQuery.WebKit.AjaxCallBackMode.Search:
                //    this.PerformRequestData();
                //    return;

                case JQuery.WebKit.AjaxCallBackMode.EditRow:
                    this.PerformRowEdit();
                    return;

                case JQuery.WebKit.AjaxCallBackMode.AddRow:
                    this.PerformRowAdd();
                    return;

                case JQuery.WebKit.AjaxCallBackMode.DeleteRow:
                    this.PerformRowDelete();
                    return;
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this._sr = new JavaScriptSerializer();
        }

        protected override void OnPreRender(EventArgs e)
        {
            Page.Resources.Add(new WebScriptResource(typeof(WebGrid), this.ClientID, ResourceType.Javascript, "JQuery.WebKit.WebGrid.locale.grid.locale-en.js"));
            Page.Resources.Add(new WebScriptResource(typeof(WebGrid), this.ClientID, ResourceType.Javascript, "JQuery.WebKit.WebGrid.WebGrid.js"));

            if (this.Page != null)
            {
                if (this.IsGridRequest())
                {
                    this.ProcessCallBack();
                }
                else// if (!Page.IsRefresh)
                {

                    bool canRegister = !Page.IsRefresh;
                    if (!canRegister)
                    {
                        string updaterId = (string)Page.PageData["target"];
                        JUpdater pnl = null;
                        if (!string.IsNullOrEmpty(updaterId))
                        {
                            pnl = (JUpdater)this.FindParent<JUpdater>(item => item != null && item.ClientID == updaterId);
                        }
                        canRegister = pnl != null;
                    }

                    if (canRegister)
                    {
                        this.EnforceColumnContraints();
                        string script = ((this.HierarchySettings.HierarchyMode == HierarchyMode.Child) || (this.HierarchySettings.HierarchyMode == HierarchyMode.ParentAndChild)) ? this.GetChildSubGridJavaScript() : this.GetStartupJavascript();
                        Page.Resources.Add(new WebScriptResource(typeof(WebGrid), this.ClientID, ResourceType.Javascript, script, LoadEvent.NA));
                    }
                }
            }
            base.OnPreRender(e);
        }

        protected internal virtual void OnRowAdded(EventArgs e)
        {
            EventHandler handler = (EventHandler)base.Events[EventRowAdded];
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected internal virtual void OnRowAdding(WebGridRowAddEventArgs e)
        {
            WebGridRowAddEventHandler handler = (WebGridRowAddEventHandler)base.Events[EventRowAdding];
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected internal virtual void OnRowDeleted(EventArgs e)
        {
            EventHandler handler = (EventHandler)base.Events[EventRowDeleted];
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected internal virtual void OnRowDeleting(WebGridRowDeleteEventArgs e)
        {
            WebGridRowDeleteEventHandler handler = (WebGridRowDeleteEventHandler)base.Events[EventRowDeleting];
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected internal virtual void OnRowEdited(EventArgs e)
        {
            EventHandler handler = (EventHandler)base.Events[EventRowEdited];
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected internal virtual void OnRowEditing(WebGridRowEditEventArgs e)
        {
            WebGridRowEditEventHandler handler = (WebGridRowEditEventHandler)base.Events[EventRowEditing];
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected internal virtual void OnRowSelecting(WebGridRowSelectEventArgs e)
        {
            WebGridRowSelectEventHandler handler = (WebGridRowSelectEventHandler)base.Events[EventRowSelecting];
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected internal virtual void OnSearched(EventArgs e)
        {
            EventHandler handler = (EventHandler)base.Events[EventSearched];
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected internal virtual void OnSearching(WebGridSearchEventArgs e)
        {
            WebGridSearchEventHandler handler = (WebGridSearchEventHandler)base.Events[EventSearching];
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected virtual void OnSorted(EventArgs e)
        {
            EventHandler handler = (EventHandler)base.Events[EventSorted];
            if (handler != null)
            {
                handler(this, e);
            }
        }

        protected virtual void OnSorting(WebGridSortEventArgs e)
        {
            bool isBoundUsingDataSourceID = base.IsBoundUsingDataSourceID;
            WebGridSortEventHandler handler = (WebGridSortEventHandler)base.Events[EventSorting];
            if (handler != null)
            {
                handler(this, e);
            }
        }

        private void PerformRequestData()
        {
            int num = Convert.ToInt32(HttpContext.Current.Request.QueryString["rows"]);
            int num2 = Convert.ToInt32(HttpContext.Current.Request.QueryString["page"]);
            //string sortExpression = HttpContext.Current.Request.QueryString["sidx"];
            //string sortDirection = HttpContext.Current.Request.QueryString["sord"];
            //string search = HttpContext.Current.Request.QueryString["_search"];
            //DataView defaultView = this.GetDataTableFromIEnumerable(retrievedData).DefaultView;
            //DataSourceView defaultView = this.GetData();
            DataTable dt = base.DataSource as DataTable;
            if (dt == null)
            {
                return;
            }
            //if (this._selectArguments.TotalRowCount > -1)
            //{
            //    this._totalRows = this._selectArguments.TotalRowCount;
            //}
            int num3 = (this._totalRows > 0) ? this._totalRows : dt.Rows.Count;
            int num4 = (int)Math.Ceiling((double)(((float)num3) / ((float)num)));
            num2 = (num2 > num4) ? num4 : num2;
            int startIndex = (num2 * num) - num;
            if (startIndex < 0)
            {
                startIndex = 0;
            }
            int endIndex = (num3 > (num2 * num)) ? (startIndex + num) : num3;
            int num7 = (num3 > (num2 * num)) ? num : (endIndex - startIndex);
            if (this._totalRows > 0)
            {
                startIndex = 0;
                endIndex = dt.Rows.Count;
            }
            if (((WebGridDataRequestedEventHandler)base.Events[EventDataRequested]) != null)
            {
                DataTable table2 = this.GetPagedDataTable(startIndex, endIndex, dt);
                this.OnDataRequested(new WebGridDataRequestedEventArgs(table2));
            }
            JsonResponse response = new JsonResponse();
            response.page = (num2 > num4) ? num4 : num2;
            response.total = num4;
            response.records = num3;
            response.rows = new JsonRow[num7];
            response.userdata = this.GetFooterInfo();
            int num8 = 0;
            for (int i = startIndex; i < endIndex; i++)
            {
                string[] strArray = new string[this.Columns.Count];
                for (int j = 0; j < this.Columns.Count; j++)
                {
                    WebGridColumn column = this.Columns[j];
                    string str4 = "";
                    if (!string.IsNullOrEmpty(column.DataField) && dt.Columns.Contains(column.DataField))
                    {
                        int ordinal = dt.Columns[column.DataField].Ordinal;
                        str4 = string.IsNullOrEmpty(column.DataFormatString) ? dt.Rows[i].ItemArray[ordinal].ToString() : column.FormatDataValue(dt.Rows[i].ItemArray[ordinal], column.HtmlEncode);
                    }
                    strArray[j] = str4;
                }
                string rowKey = strArray[this.GetPrimaryKeyIndex()];
                for (int k = 0; k < this.Columns.Count; k++)
                {
                    WebGridCellBindEventArgs e = new WebGridCellBindEventArgs(strArray[k], k, i, rowKey, dt.Rows[i].ItemArray);
                    this.OnCellBinding(e);
                    strArray[k] = e.CellHtml;
                    this.OnCellBound(e);
                }
                JsonRow row = new JsonRow();
                row.id = rowKey;
                row.cell = strArray;
                response.rows[num8++] = row;
            }
            this.EmitResponse(this._sr.Serialize(response));
        }

        private void PerformRowAdd()
        {
            NameValueCollection values = new NameValueCollection();
            foreach (string str in HttpContext.Current.Request.Form.Keys)
            {
                values[str] = HttpContext.Current.Request.Form[str];
            }
            WebGridRowAddEventArgs e = new WebGridRowAddEventArgs();
            e.RowData = values;
            string str2 = HttpContext.Current.Request.QueryString["parentRowID"];
            if (!string.IsNullOrEmpty(str2))
            {
                e.ParentRowKey = str2;
            }
            this.OnRowAdding(e);
            if (!e.Cancel)
            {
                this.HandleInsert(e);
            }
            this.OnRowAdded(new EventArgs());
        }

        private void PerformRowDelete()
        {
            NameValueCollection values = new NameValueCollection();
            foreach (string str in HttpContext.Current.Request.Form.Keys)
            {
                values[str] = HttpContext.Current.Request.Form[str];
            }
            WebGridRowDeleteEventArgs e = new WebGridRowDeleteEventArgs();
            e.RowKey = values["id"];
            this.OnRowDeleting(e);
            if (!e.Cancel)
            {
                this.HandleDelete(e);
            }
            this.OnRowDeleted(new EventArgs());
        }

        private void PerformRowEdit()
        {
            NameValueCollection values = new NameValueCollection();
            foreach (string str in HttpContext.Current.Request.Form.Keys)
            {
                if (str != "oper")
                {
                    values[str] = HttpContext.Current.Request.Form[str];
                }
            }
            string dataField = string.Empty;
            foreach (WebGridColumn column in this.Columns)
            {
                if (column.PrimaryKey)
                {
                    dataField = column.DataField;
                    break;
                }
            }
            if (!string.IsNullOrEmpty(dataField) && !string.IsNullOrEmpty(values["id"]))
            {
                values[dataField] = values["id"];
            }
            WebGridRowEditEventArgs e = new WebGridRowEditEventArgs();
            e.RowData = values;
            e.RowKey = values["id"];
            string str3 = HttpContext.Current.Request.QueryString["parentRowID"];
            if (!string.IsNullOrEmpty(str3))
            {
                e.ParentRowKey = str3;
            }
            this.OnRowEditing(e);
            if (!e.Cancel)
            {
                this.HandleUpdate(e);
            }
            this.OnRowEdited(new EventArgs());
        }

        private SearchCriteriaCollection PerformSearch(string search)
        {
            SearchCriteriaCollection searchCollection = null;
            if (!string.IsNullOrEmpty(search) && Convert.ToBoolean(search))
            {
                string str = HttpContext.Current.Request.QueryString["filters"];
                string str2 = HttpContext.Current.Request.QueryString["searchField"];
                string searchString = HttpContext.Current.Request.QueryString["searchString"];
                string searchOperation = HttpContext.Current.Request.QueryString["searchOper"];
                if (string.IsNullOrEmpty(str) && !string.IsNullOrEmpty(str2))
                {
                    searchCollection = new JQuery.WebKit.Searching(this, str2, searchString, searchOperation).PerformSearch(search);
                }
                else if (!string.IsNullOrEmpty(str))
                {
                    searchCollection = new MultipleSearching(this, str).PerformSearch();
                }
                else if (this.ToolBarSettings.ShowSearchToolBar)
                {
                    searchCollection = new ToolBarSearching(this).PerformSearch();
                }
            }
            return searchCollection;
        }

        private bool PerformSort(string sortExpression, string sortDirection)
        {
            if (!string.IsNullOrEmpty(sortExpression))
            {
                WebGridSortEventArgs e = new WebGridSortEventArgs(sortExpression, sortDirection);
                this.OnSorting(e);
                if (e.Cancel)
                {
                    return false;
                }
                this.OnSorted(new EventArgs());
                return true;
            }
            return false;
        }

        private void ProcessCallBack()
        {
            int newPageIndex = Convert.ToInt32(HttpContext.Current.Request.QueryString["page"]);
            int num2 = Convert.ToInt32(HttpContext.Current.Request.QueryString["rows"]);
            string sortExpression = HttpContext.Current.Request.QueryString["sidx"];
            string sortDirection = HttpContext.Current.Request.QueryString["sord"];
            string search = HttpContext.Current.Request.QueryString["_search"];
            string parentRowKey = HttpContext.Current.Request.QueryString["parentRowID"];
            this.PagerSettings.CurrentPage = newPageIndex;
            this.PagerSettings.PageSize = num2;
            SearchCriteriaCollection searchCriteriaList = null;
            if (((WebGridDataRequestEventHandler)base.Events[EventDataRequesting]) != null)
            {
                switch (this.AjaxCallBackMode)
                {
                    case JQuery.WebKit.AjaxCallBackMode.RequestData:
                    case JQuery.WebKit.AjaxCallBackMode.Search:
                        this.PerformSearch(search);
                        if (!this._dataSourceSorted)
                        {
                            this.PerformSort(sortExpression, sortDirection);
                        }
                        else
                        {
                            new WebGridSortEventArgs(sortExpression, sortDirection);
                            this.OnSorted(new EventArgs());
                        }
                        break;
                }
                string whereClause = this.GetWhereClause(search, false, out searchCriteriaList);
                WebGridDataRequestEventArgs e = new WebGridDataRequestEventArgs(sortExpression, sortDirection, newPageIndex, whereClause, parentRowKey);
                this.OnDataRequesting(e);
                if (e.TotalRows > 0)
                {
                    this._totalRows = e.TotalRows;
                }
                switch (this.AjaxCallBackMode)
                {
                    case JQuery.WebKit.AjaxCallBackMode.RequestData:
                    case JQuery.WebKit.AjaxCallBackMode.Search:
                        this.PerformRequestData();
                        break;
                }
            }
            if (this.IsGridRequest())
            {
                //this._selectArguments = this.CreateDataSourceSelectArguments();
                //ICollection lst = base.GetViewNames();
                this.OnDataSourceViewSelectCallback();
                //this.GetData().Select(this._selectArguments, new DataSourceViewSelectCallback(this.OnDataSourceViewSelectCallback));
            }
        }

        //public DataSourceView GetData()
        //{
        //    return base.GetData();
        //    DataTable dt = this.DataSource as DataTable;
        //    if (dt == null)
        //    {
        //        dt = new DataTable();
        //    }
        //    //return new DataSourceView
        //}

        public void RaisePostBackEvent(string eventArgument)
        {
            this.SelectedRow = eventArgument;
            WebGridRowSelectEventArgs e = new WebGridRowSelectEventArgs();
            e.RowKey = eventArgument;
            this.OnRowSelecting(e);
        }

        public void RaisePostDataChangedEvent()
        {
        }

        protected override void Render(HtmlTextWriter writer)
        {
            if (!base.DesignMode)
            {
                this.RenderGridHtml(writer);
                if (this.ToolBarSettings.ToolBarPosition != ToolBarPosition.Hidden)
                {
                    this.RenderPagerHtml(writer);
                }
                this.RenderHidden(writer);
            }
        }

        private void RenderClientSideEvent(StringBuilder sb, string eventName, string jsName)
        {
            if (!string.IsNullOrEmpty(eventName))
            {
                sb.AppendFormat(",{0}:{1}", jsName, eventName);
            }
        }

        private void RenderClientSideEvents(StringBuilder sb, JQuery.WebKit.ClientSideEvents e)
        {
            this.RenderClientSideEvent(sb, e.BeforeAjaxRequest, "beforeRequest");
            this.RenderClientSideEvent(sb, e.BeforeRowSelect, "beforeSelectRow");
            this.RenderClientSideEvent(sb, e.GridInitialized, "gridComplete");
            this.RenderClientSideEvent(sb, e.LoadComplete, "loadComplete");
            this.RenderClientSideEvent(sb, e.LoadDataError, "loadError");
            this.RenderClientSideEvent(sb, e.CellSelect, "onCellSelect");
            this.RenderClientSideEvent(sb, e.RowDoubleClick, "ondblClickRow");
            this.RenderClientSideEvent(sb, e.BeforePageChange, "onPaging");
            this.RenderClientSideEvent(sb, e.RowRightClick, "onRightClickRow");
            this.RenderClientSideEvent(sb, e.RowSelect, "onSelectRow");
            this.RenderClientSideEvent(sb, e.ColumnSort, "onSortCol");
            this.RenderClientSideEvent(sb, e.SubGridBeforeRowExpand, "subGridBeforeExpand");
            this.RenderClientSideEvent(sb, e.SubGridRowExpanded, "subGridRowExpanded");
            this.RenderClientSideEvent(sb, e.SubGridRowCollapsed, "subGridRowColapsed");
            this.RenderClientSideEvent(sb, e.AfterEditCell, "afterEditCell");
            this.RenderClientSideEvent(sb, e.AfterSaveCell, "afterSaveCell");
            this.RenderClientSideEvent(sb, e.AfterSubmitCell, "afterSubmitCell");
            this.RenderClientSideEvent(sb, e.BeforeEditCell, "beforeEditCell");
            this.RenderClientSideEvent(sb, e.BeforeSaveCell, "beforeSaveCell");
            this.RenderClientSideEvent(sb, e.BeforeSubmitCell, "beforeSubmitCell");
            this.RenderClientSideEvent(sb, e.BeforeSubmitCell, "beforeSubmitCell");
            this.RenderClientSideEvent(sb, e.EditCellFormat, "formatCell");
            this.RenderClientSideEvent(sb, e.EditError, "errorCell");
            this.RenderClientSideEvent(sb, e.OnSelectAll, "onSelectAll");
            if (string.IsNullOrEmpty(e.LoadDataError))
            {
                this.RenderClientSideEvent(sb, "WebGrid_aspnet_loadErrorHandler", "loadError");
            }
        }

        private void RenderGridHtml(HtmlTextWriter writer)
        {
            writer.WriteBeginTag("table");
            writer.WriteAttribute("id", this.ClientID);
            writer.Write('>');
            writer.WriteEndTag("table");
        }

        private void RenderHidden(HtmlTextWriter writer)
        {
            writer.WriteBeginTag("input");
            writer.WriteAttribute("id", this.UniqueID + "_SelectedRow");
            writer.WriteAttribute("name", this.UniqueID);
            writer.WriteAttribute("type", "hidden");
            writer.Write('>');
            writer.WriteEndTag("input");
            writer.WriteBeginTag("input");
            writer.WriteAttribute("id", this.UniqueID + "_CurrentPage");
            writer.WriteAttribute("name", this.UniqueID);
            writer.WriteAttribute("type", "hidden");
            writer.Write('>');
            writer.WriteEndTag("input");
        }

        private void RenderPagerHtml(HtmlTextWriter writer)
        {
            writer.WriteBeginTag("div");
            writer.WriteAttribute("id", this.ClientID + "_pager");
            writer.Write('>');
            writer.WriteEndTag("div");
        }

        private void ResolveAjaxCallBackMode()
        {
            this._ajaxCallModeResolved = true;
            if (this.IsGridRequest())
            {
                string str4;
                string str = HttpContext.Current.Request.Form["oper"];
                string str2 = HttpContext.Current.Request.QueryString["editMode"];
                string str3 = HttpContext.Current.Request.QueryString["_search"];
                this._ajaxCallBackMode = JQuery.WebKit.AjaxCallBackMode.RequestData;
                if (!string.IsNullOrEmpty(str) && ((str4 = str) != null))
                {
                    if (str4 == "add")
                    {
                        this._ajaxCallBackMode = JQuery.WebKit.AjaxCallBackMode.AddRow;
                        return;
                    }
                    if (str4 == "edit")
                    {
                        this._ajaxCallBackMode = JQuery.WebKit.AjaxCallBackMode.EditRow;
                        return;
                    }
                    if (str4 == "del")
                    {
                        this._ajaxCallBackMode = JQuery.WebKit.AjaxCallBackMode.DeleteRow;
                        return;
                    }
                }
                if (!string.IsNullOrEmpty(str2))
                {
                    this._ajaxCallBackMode = JQuery.WebKit.AjaxCallBackMode.EditRow;
                }
                if (!string.IsNullOrEmpty(str3) && Convert.ToBoolean(str3))
                {
                    this._ajaxCallBackMode = JQuery.WebKit.AjaxCallBackMode.Search;
                }
            }
        }

        private string RestoreSelectedState()
        {
            if (!string.IsNullOrEmpty(this.SelectedRow))
            {
                StringBuilder builder = new StringBuilder();
                builder.AppendFormat("\r\n                        jQuery('#{0}').setGridParam( {{ gridComplete: function() \r\n                        {{                            \r\n                            var grid = jQuery('#{0}');\r\n                            grid.setSelection('{1}',false);\r\n                        }}\r\n                     }});\r\n\r\n                ", this.ClientID, this.SelectedRow);
                return builder.ToString();
            }
            return string.Empty;
        }

        protected override object SaveViewState()
        {
            object obj2 = base.SaveViewState();
            object obj3 = (this._toolBarSettings != null) ? ((IStateManager)this._toolBarSettings).SaveViewState() : null;
            object obj4 = (this._editDialogSettings != null) ? ((IStateManager)this._editDialogSettings).SaveViewState() : null;
            object obj5 = (this._searchDialogSettings != null) ? ((IStateManager)this._searchDialogSettings).SaveViewState() : null;
            object obj6 = (this._pagerSettings != null) ? ((IStateManager)this._pagerSettings).SaveViewState() : null;
            object obj7 = (this._sortSettings != null) ? ((IStateManager)this._sortSettings).SaveViewState() : null;
            object obj8 = (this._appearanceSettings != null) ? ((IStateManager)this._appearanceSettings).SaveViewState() : null;
            object obj9 = (this._addDialogSettings != null) ? ((IStateManager)this._addDialogSettings).SaveViewState() : null;
            object obj10 = (this._deleteDialogSettings != null) ? ((IStateManager)this._deleteDialogSettings).SaveViewState() : null;
            object obj11 = (this._editInlineCellSettings != null) ? ((IStateManager)this._editInlineCellSettings).SaveViewState() : null;
            object obj12 = (this._groupSettings != null) ? ((IStateManager)this._groupSettings).SaveViewState() : null;
            return new object[] { obj2, obj3, obj4, obj5, obj6, obj7, obj8, obj9, obj10, obj11, obj12 };
        }

        public void ShowEditValidationMessage(string errorMessage)
        {
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.StatusCode = 500;
            HttpContext.Current.Response.StatusDescription = errorMessage;
            HttpContext.Current.Response.Write(errorMessage);
            HttpContext.Current.Response.End();
        }

        protected override void TrackViewState()
        {
            base.TrackViewState();
            if (this._toolBarSettings != null)
            {
                ((IStateManager)this._toolBarSettings).TrackViewState();
            }
            if (this._editDialogSettings != null)
            {
                ((IStateManager)this._editDialogSettings).TrackViewState();
            }
            if (this._searchDialogSettings != null)
            {
                ((IStateManager)this._searchDialogSettings).TrackViewState();
            }
            if (this._pagerSettings != null)
            {
                ((IStateManager)this._pagerSettings).TrackViewState();
            }
            if (this._sortSettings != null)
            {
                ((IStateManager)this._sortSettings).TrackViewState();
            }
            if (this._appearanceSettings != null)
            {
                ((IStateManager)this._appearanceSettings).TrackViewState();
            }
            if (this._addDialogSettings != null)
            {
                ((IStateManager)this._addDialogSettings).TrackViewState();
            }
            if (this._deleteDialogSettings != null)
            {
                ((IStateManager)this._deleteDialogSettings).TrackViewState();
            }
            if (this._toolBarSettings != null)
            {
                ((IStateManager)this._toolBarSettings).TrackViewState();
            }
            if (this._editInlineCellSettings != null)
            {
                ((IStateManager)this._editInlineCellSettings).TrackViewState();
            }
            if (this._groupSettings != null)
            {
                ((IStateManager)this._groupSettings).TrackViewState();
            }
        }

        [EditorBrowsable(EditorBrowsableState.Never), Browsable(false)]
        public override string AccessKey
        {
            get
            {
                return base.AccessKey;
            }
            set
            {
                base.AccessKey = value;
            }
        }

        [Category("Settings"), PersistenceMode(PersistenceMode.InnerProperty), Description("Settings related to UI/Functionality of the Add Dialog in WebGrid"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), NotifyParentProperty(true)]
        public virtual JQuery.WebKit.AddDialogSettings AddDialogSettings
        {
            get
            {
                if (this._addDialogSettings == null)
                {
                    this._addDialogSettings = new JQuery.WebKit.AddDialogSettings();
                    if (base.IsTrackingViewState)
                    {
                        ((IStateManager)this._addDialogSettings).TrackViewState();
                    }
                }
                return this._addDialogSettings;
            }
        }

        public JQuery.WebKit.AjaxCallBackMode AjaxCallBackMode
        {
            get
            {
                if (!this._ajaxCallModeResolved)
                {
                    this.ResolveAjaxCallBackMode();
                }
                return this._ajaxCallBackMode;
            }
        }

        [Description("Settings related to appearance in WebGrid"), PersistenceMode(PersistenceMode.InnerProperty), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Category("Settings"), NotifyParentProperty(true)]
        public virtual JQuery.WebKit.AppearanceSettings AppearanceSettings
        {
            get
            {
                if (this._appearanceSettings == null)
                {
                    this._appearanceSettings = new JQuery.WebKit.AppearanceSettings();
                    if (base.IsTrackingViewState)
                    {
                        ((IStateManager)this._appearanceSettings).TrackViewState();
                    }
                }
                return this._appearanceSettings;
            }
        }

        [DefaultValue(false)]
        public bool AutoWidth
        {
            get
            {
                object obj2 = this.ViewState["AutoWidth"];
                if (obj2 == null)
                {
                    return false;
                }
                return (bool)obj2;
            }
            set
            {
                this.ViewState["AutoWidth"] = value;
            }
        }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override Color BackColor
        {
            get
            {
                return base.BackColor;
            }
            set
            {
                base.BackColor = value;
            }
        }

        [EditorBrowsable(EditorBrowsableState.Never), Browsable(false)]
        public override Color BorderColor
        {
            get
            {
                return base.BorderColor;
            }
            set
            {
                base.BorderColor = value;
            }
        }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override System.Web.UI.WebControls.BorderStyle BorderStyle
        {
            get
            {
                return base.BorderStyle;
            }
            set
            {
                base.BorderStyle = value;
            }
        }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override Unit BorderWidth
        {
            get
            {
                return base.BorderWidth;
            }
            set
            {
                base.BorderWidth = value;
            }
        }

        [Description("Defines client-side events in WebGrid"), Category("Client-side events"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), NotifyParentProperty(true), PersistenceMode(PersistenceMode.InnerProperty)]
        public virtual JQuery.WebKit.ClientSideEvents ClientSideEvents
        {
            get
            {
                if (this._clientSideEvents == null)
                {
                    this._clientSideEvents = new JQuery.WebKit.ClientSideEvents();
                    if (base.IsTrackingViewState)
                    {
                        ((IStateManager)this._clientSideEvents).TrackViewState();
                    }
                }
                return this._clientSideEvents;
            }
        }

        [Description("Whether or not columns re-ordering is enabled. Default is false."), DefaultValue(false)]
        public bool ColumnReordering
        {
            get
            {
                object obj2 = this.ViewState["ColumnReordering"];
                if (obj2 == null)
                {
                    return false;
                }
                return (bool)obj2;
            }
            set
            {
                this.ViewState["ColumnReordering"] = value;
            }
        }

        [DefaultValue((string)null), Description("DataControls_Columns"), Category("Default"), MergableProperty(false), PersistenceMode(PersistenceMode.InnerProperty)]
        public virtual WebGridColumnCollection Columns
        {
            get
            {
                if (this._columnCollection == null)
                {
                    this._columnCollection = new WebGridColumnCollection();
                    if (base.IsTrackingViewState)
                    {
                        ((IStateManager)this._columnCollection).TrackViewState();
                    }
                }
                return this._columnCollection;
            }
        }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override string CssClass
        {
            get
            {
                return base.CssClass;
            }
            set
            {
                base.CssClass = value;
            }
        }

        [Category(""), DefaultValue("")]
        public string DataUrl
        {
            get
            {
                object obj2 = this.ViewState["DataUrl"];
                if (obj2 != null)
                {
                    return (string)obj2;
                }
                if (base.DesignMode)
                {
                    return "";
                }
                return HttpContext.Current.Request.Url.PathAndQuery;
            }
            set
            {
                this.ViewState["DataUrl"] = value;
            }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content), NotifyParentProperty(true), PersistenceMode(PersistenceMode.InnerProperty), Description("Settings related to UI/Functionality of the Delete Dialog in WebGrid"), Category("Settings")]
        public virtual JQuery.WebKit.DeleteDialogSettings DeleteDialogSettings
        {
            get
            {
                if (this._deleteDialogSettings == null)
                {
                    this._deleteDialogSettings = new JQuery.WebKit.DeleteDialogSettings();
                    if (base.IsTrackingViewState)
                    {
                        ((IStateManager)this._deleteDialogSettings).TrackViewState();
                    }
                }
                return this._deleteDialogSettings;
            }
        }

        [PersistenceMode(PersistenceMode.InnerProperty), Category("Settings"), Description("Settings related to UI/Functionality of the Edit Dialog in WebGrid"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), NotifyParentProperty(true)]
        public virtual JQuery.WebKit.EditDialogSettings EditDialogSettings
        {
            get
            {
                if (this._editDialogSettings == null)
                {
                    this._editDialogSettings = new JQuery.WebKit.EditDialogSettings();
                    if (base.IsTrackingViewState)
                    {
                        ((IStateManager)this._editDialogSettings).TrackViewState();
                    }
                }
                return this._editDialogSettings;
            }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Description("Settings related to Inline Cell Editing in WebGrid"), NotifyParentProperty(true), Category("Settings"), PersistenceMode(PersistenceMode.InnerProperty)]
        public virtual JQuery.WebKit.EditInlineCellSettings EditInlineCellSettings
        {
            get
            {
                if (this._editInlineCellSettings == null)
                {
                    this._editInlineCellSettings = new JQuery.WebKit.EditInlineCellSettings();
                    if (base.IsTrackingViewState)
                    {
                        ((IStateManager)this._editInlineCellSettings).TrackViewState();
                    }
                }
                return this._editInlineCellSettings;
            }
        }

        [DefaultValue(""), Category("")]
        public string EditUrl
        {
            get
            {
                object obj2 = this.ViewState["EditUrl"];
                if (obj2 != null)
                {
                    return (string)obj2;
                }
                if (base.DesignMode)
                {
                    return "";
                }
                return HttpContext.Current.Request.Url.PathAndQuery;
            }
            set
            {
                this.ViewState["EditUrl"] = value;
            }
        }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override FontInfo Font
        {
            get
            {
                return base.Font;
            }
        }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override Color ForeColor
        {
            get
            {
                return base.ForeColor;
            }
            set
            {
                base.ForeColor = value;
            }
        }

        [PersistenceMode(PersistenceMode.InnerProperty), MergableProperty(false), DefaultValue((string)null), Category("Settings"), Description("Settings related to Grouping"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), NotifyParentProperty(true)]
        public virtual JQuery.WebKit.GroupSettings GroupSettings
        {
            get
            {
                if (this._groupSettings == null)
                {
                    this._groupSettings = new JQuery.WebKit.GroupSettings();
                    if (base.IsTrackingViewState)
                    {
                        ((IStateManager)this._groupSettings).TrackViewState();
                    }
                }
                return this._groupSettings;
            }
        }

        [NotifyParentProperty(true), PersistenceMode(PersistenceMode.InnerProperty), Description("Settings related to Hierarchy in WebGrid"), Category("Settings"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public virtual JQuery.WebKit.HierarchySettings HierarchySettings
        {
            get
            {
                if (this._hierarchySettings == null)
                {
                    this._hierarchySettings = new JQuery.WebKit.HierarchySettings();
                    if (base.IsTrackingViewState)
                    {
                        ((IStateManager)this._hierarchySettings).TrackViewState();
                    }
                }
                return this._hierarchySettings;
            }
        }

        [DefaultValue(false)]
        public bool MultiSelect
        {
            get
            {
                object obj2 = this.ViewState["MultiSelect"];
                if (obj2 == null)
                {
                    return false;
                }
                return (bool)obj2;
            }
            set
            {
                this.ViewState["MultiSelect"] = value;
            }
        }

        [DefaultValue(0)]
        public JQuery.WebKit.MultiSelectKey MultiSelectKey
        {
            get
            {
                object obj2 = this.ViewState["MultiSelectKey"];
                if (obj2 == null)
                {
                    return JQuery.WebKit.MultiSelectKey.None;
                }
                return (JQuery.WebKit.MultiSelectKey)obj2;
            }
            set
            {
                this.ViewState["MultiSelectKey"] = value;
            }
        }

        [DefaultValue(1)]
        public JQuery.WebKit.MultiSelectMode MultiSelectMode
        {
            get
            {
                object obj2 = this.ViewState["MultiSelectMode"];
                if (obj2 == null)
                {
                    return JQuery.WebKit.MultiSelectMode.SelectOnRowClick;
                }
                return (JQuery.WebKit.MultiSelectMode)obj2;
            }
            set
            {
                this.ViewState["MultiSelectMode"] = value;
            }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content), NotifyParentProperty(true), Category("Settings"), PersistenceMode(PersistenceMode.InnerProperty), Description("Settings related to UI/Functionality of paging in WebGrid")]
        public virtual JQuery.WebKit.PagerSettings PagerSettings
        {
            get
            {
                if (this._pagerSettings == null)
                {
                    this._pagerSettings = new JQuery.WebKit.PagerSettings();
                    if (base.IsTrackingViewState)
                    {
                        ((IStateManager)this._pagerSettings).TrackViewState();
                    }
                }
                return this._pagerSettings;
            }
        }

        [DefaultValue(0), Description("The rendering mode of the grid. Default is 'Default'. Optimized may speed the grid up, but does not support all functionality.")]
        public JQuery.WebKit.RenderingMode RenderingMode
        {
            get
            {
                object obj2 = this.ViewState["RenderingMode"];
                if (obj2 == null)
                {
                    return JQuery.WebKit.RenderingMode.Default;
                }
                return (JQuery.WebKit.RenderingMode)obj2;
            }
            set
            {
                this.ViewState["RenderingMode"] = value;
            }
        }

        [Description("Settings related to UI/Functionality of the Search Dialog in WebGrid"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), NotifyParentProperty(true), PersistenceMode(PersistenceMode.InnerProperty), Category("Settings")]
        public virtual JQuery.WebKit.SearchDialogSettings SearchDialogSettings
        {
            get
            {
                if (this._searchDialogSettings == null)
                {
                    this._searchDialogSettings = new JQuery.WebKit.SearchDialogSettings();
                    if (base.IsTrackingViewState)
                    {
                        ((IStateManager)this._searchDialogSettings).TrackViewState();
                    }
                }
                return this._searchDialogSettings;
            }
        }

        [DefaultValue(""), Category("ToolBar")]
        public string SelectedRow
        {
            get
            {
                object obj2 = this.ViewState["SelectedRow"];
                if (obj2 == null)
                {
                    return "";
                }
                return (string)obj2;
            }
            set
            {
                this.ViewState["SelectedRow"] = value;
            }
        }

        private bool ShowToolBar
        {
            get
            {
                if (((!this.ToolBarSettings.ShowAddButton && !this.ToolBarSettings.ShowDeleteButton) && (!this.ToolBarSettings.ShowEditButton && !this.ToolBarSettings.ShowRefreshButton)) && !this.ToolBarSettings.ShowSearchButton)
                {
                    return this.ToolBarSettings.ShowViewRowDetailsButton;
                }
                return true;
            }
        }

        [Description("Settings related to UI/Functionality of sorting in WebGrid"), PersistenceMode(PersistenceMode.InnerProperty), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), NotifyParentProperty(true), Category("Settings")]
        public virtual JQuery.WebKit.SortSettings SortSettings
        {
            get
            {
                if (this._sortSettings == null)
                {
                    this._sortSettings = new JQuery.WebKit.SortSettings();
                    if (base.IsTrackingViewState)
                    {
                        ((IStateManager)this._sortSettings).TrackViewState();
                    }
                }
                return this._sortSettings;
            }
        }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override short TabIndex
        {
            get
            {
                return base.TabIndex;
            }
            set
            {
                base.TabIndex = value;
            }
        }

        [PersistenceMode(PersistenceMode.InnerProperty), Category("Settings"), Description("Settings related to UI/Functionality of the ToolBar in WebGrid"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), NotifyParentProperty(true)]
        public virtual JQuery.WebKit.ToolBarSettings ToolBarSettings
        {
            get
            {
                if (this._toolBarSettings == null)
                {
                    this._toolBarSettings = new JQuery.WebKit.ToolBarSettings();
                    if (base.IsTrackingViewState)
                    {
                        ((IStateManager)this._toolBarSettings).TrackViewState();
                    }
                }
                return this._toolBarSettings;
            }
        }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override string ToolTip
        {
            get
            {
                return base.ToolTip;
            }
            set
            {
                base.ToolTip = value;
            }
        }

        public delegate void WebGridCellBindEventHandler(object sender, WebGridCellBindEventArgs e);

        public delegate void WebGridDataRequestedEventHandler(object sender, WebGridDataRequestedEventArgs e);

        public delegate void WebGridDataRequestEventHandler(object sender, WebGridDataRequestEventArgs e);

        public delegate void WebGridRowAddEventHandler(object sender, WebGridRowAddEventArgs e);

        public delegate void WebGridRowDeleteEventHandler(object sender, WebGridRowDeleteEventArgs e);

        public delegate void WebGridRowEditEventHandler(object sender, WebGridRowEditEventArgs e);

        public delegate void WebGridRowSelectEventHandler(object sender, WebGridRowSelectEventArgs e);

        public delegate void WebGridSearchEventHandler(object sender, WebGridSearchEventArgs e);

        public delegate void WebGridSortEventHandler(object sender, WebGridSortEventArgs e);
    }
}

